<?php $this->load->view('_inc/header'); ?>
<script>
$(document).ready(function(){
   $('.cadastrar').click(function(){
           var divEditar = $('.popUp');
           $.ajax({
                url: '<?php echo base_url()?>index.php/disciplina/cadastrar',
                type: 'POST',
                success: function(data){
                    divEditar.html(data);
                    abrePopUp();
                }
        });
    }); 
    
    $('.editar').click(function(){
           var id = $(this).attr('id');
           var divEditar = $('.popUp');
           $.ajax({
                url: '<?php echo base_url()?>index.php/disciplina/editar/' + id,
                type: 'POST',
                success: function(data){
                    divEditar.html(data);
                    abrePopUp();
                }
        });
    });
    
    $('.excluir').click(function(){      
        if(confirm("Deseja realmente excluir esta disciplina?")){
            var id = $(this).attr('id');
            var url = $(this).attr('name');
            $(this).parent('td').parent('tr').css('background','#ff9999').hide(600);
            $.ajax({
                url: '<?php echo base_url()?>index.php/disciplina/excluir/' + id,
                type: 'POST',
            });
        }
    });
    
});
</script>
<div id="areaTroca"></div>

<button class="cadastrar">Nova Disciplina</button>
<div id="pesquisa">
    <img src="<?php echo base_url()?>public/imagens/icones/pesquisar.png"/>
    <input id="pesquisar">
</div>

<table class="listagem">
    <thead>
        <tr>
            <th>Nome</th>
            <th>Créditos</th>
            <th>Curso</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach($disciplinas as $disciplina) : ?>
        <tr>
            <td><?php echo $disciplina->disciplina?></td>
            <td><?php echo $disciplina->creditos?></td>
            <td><?php echo $disciplina->curso?></td>
            <?php if(!$this->session->userdata('perfil')){ ?>
                <td><a class="icone editar" id="<?php echo $disciplina->id?>"></a></td>
                <td><a class="icone excluir notcheck" id="<?php echo $disciplina->id?>"></a></td>
            <?php } ?>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>
<?php $this->load->view('_inc/footer'); ?>